package cards;

import java.util.ArrayList;

public class Deck<CardType extends Card<?>> {

	ArrayList<CardType> mCards ;

	public Deck(int aSize )
	{
	 mCards = new ArrayList<>(aSize); 	
	}
	
	public int size() {
		return mCards.size();
	}

	public CardType getCard(int aPosition) {
		CardType returnCard;

		try {
			returnCard = mCards.get(aPosition);
			mCards.remove(aPosition);
		}catch (IndexOutOfBoundsException e) {
			returnCard = null;
		}

		return returnCard;
	}

	public void putCard(CardType aCard, int aPosition) {
		mCards.add(aPosition, aCard);
	}
	
	public CardType getTopCard()
	{
		return getCard(0);
	}
	
	public void putToBottom(CardType aCard)
	{
		putCard(aCard, mCards.size());
	}
	
	public void putToTop(CardType aCard)
	{
		putCard(aCard, 0);
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("Size : "+size()+"\n");
		for (CardType card : mCards)
		{   
			sb.append("Index : " + mCards.indexOf(card) + " ");
			sb.append(card.toString());
			sb.append("\n");
		}
		
		return sb.toString();
	}
}
